package com.hxzy.yygh.hosp.controller.api;

import com.hxzy.yygh.common.result.Result;
import com.hxzy.yygh.hosp.service.DepartmentService;
import com.hxzy.yygh.hosp.service.HospitalService;
import com.hxzy.yygh.hosp.service.ScheduleService;
import com.hxzy.yygh.model.hosp.Hospital;
import com.hxzy.yygh.model.hosp.Schedule;
import com.hxzy.yygh.vo.hosp.DepartmentVo;
import com.hxzy.yygh.vo.hosp.HospitalQueryVo;
import com.hxzy.yygh.vo.hosp.ScheduleOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    //查询医院分页列表
    @ApiOperation(value = "查询医院分页列表")
    @GetMapping("list/{page}/{limit}")
    public Result index(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            HospitalQueryVo hospitalQueryVo){
        Page<Hospital> pageModel = hospitalService.selectHospByPage(page, limit, hospitalQueryVo);
        return Result.ok(pageModel);
    }

    //根据医院名称关键字搜索医院列表
    @ApiOperation(value = "根据医院名称关键字搜索医院列表")
    @GetMapping("findByHosname/{hosname}")
    public Result findByHosName(@PathVariable String hosname){
        List<Hospital> hospitalList = hospitalService.getByHosName(hosname);
        return Result.ok(hospitalList);
    }

    //根据医院编号获取科室列表
    @ApiOperation(value = "根据医院编号获取科室列表")
    @GetMapping("findDeptListByHosCode/{hoscode}")
    public Result findDeptListByHosHosCode(@PathVariable String hoscode){
        List<DepartmentVo> deptList = departmentService.findDeptList(hoscode);
        return Result.ok(deptList);
    }

    //根据医院编号，获取医院详情信息
    @ApiOperation(value = "根据医院编号获取医院详情信息")
    @GetMapping("findHosDetailsByHosCode/{hoscode}")
    public Result findHosDetailsByHosCode(@PathVariable String hoscode){
        Map<String,Object> map = hospitalService.getHosDetails(hoscode);
        return Result.ok(map);
    }

    //获取当前科室，可预约排班数据
    @ApiOperation(value = "获取当前科室，可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingScheduleRule(
            @ApiParam(name = "page" , value = "当前页", required = true)
            @PathVariable Integer page,

            @ApiParam(name = "limit" , value = "每页记录数", required = true)
            @PathVariable Integer limit,

            @ApiParam(name = "hoscode" , value = "医院编码", required = true)
            @PathVariable String hoscode,

            @ApiParam(name = "depcode" , value = "科室编码", required = true)
            @PathVariable String depcode
    ){
        //调用方法，获得当前科室的可预约排班数据
        Map<String, Object> resultMap = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);

        //返回成功状态码
        return Result.ok(resultMap);
    }

    //获取当前日期下，具体的排班数据
    @ApiOperation(value = "获取当前日期下，具体的排班数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode", value = "医院编号", required = true)
            @PathVariable String hoscode,

            @ApiParam(name = "depcode", value = "部门编号", required = true)
            @PathVariable String depcode,

            @ApiParam(name = "workDate", value = "部门编号", required = true)
            @PathVariable String workDate
    ){
        //调用方法，获得当前日期下，该科室具体排班数据
        List<Schedule> detailsSchedule = scheduleService.getDetailsSchedule(hoscode, depcode, workDate);

        //返回成功状态码
        return Result.ok(detailsSchedule);
    }

    //根据排班id获取排班数据
    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId){
        Schedule schedule = scheduleService.getScheduleById(scheduleId);
        return Result.ok(schedule);
    }


    //根据排班id获取预约下单数据
    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }


}
